package com.ylfstu.generic;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class GenericExercise {
    public static void main(String[] args) {
        HashMap<String, Student> hashMap = new HashMap<>();
        hashMap.put("jack", new Student("jack", 18));
        hashMap.put("tom", new Student("tom", 28));
        hashMap.put("mary", new Student("mary", 24));

        System.out.println("keySet遍历-----");
        Set<String> keySet = hashMap.keySet();
        Collection<Student> values = hashMap.values();
        for (String key : keySet) {
            System.out.println(key + "-" + hashMap.get(key));
        }
        System.out.println();
        Set<Map.Entry<String, Student>> entries = hashMap.entrySet();
        for (Map.Entry<String, Student> entry : entries) {
            System.out.println(entry.getKey() + "-" + entry.getValue());
        }

    }
}

class Student {
    private String name;
    private int age;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
